package org.lisy.java.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 嵌套数据转换插件
 * 
 * @author lisy
 */
public class DataPlugin {

	private final static String OBJECT_TYPE = "__type__";
	
	/**
	 * 配置说明
	 * - 组装结果默认返回list, __type__配置为object时返回第一个对象
	 * - 字段前加 ~~ 时, 返回参数不包含此字段
	 */
	public static void main(String[] args) throws JsonProcessingException {
		int count = 7;
		switch (count) {
			case 1:
				testCase1(); // 用例1 不加 tech_ic_json_config 字段，响应正确
				break;
			case 2:
				testCase2(); // 用例2 配置格式正确，content 无内容，响应正确
				break;
			case 3:
				testCase3(); // 用例3 配置格式正确，content 一层，解析正确
				break;
			case 4:
				testCase4(); // 用例4 配置格式正确，content 二层，解析正确
				break;
			case 5:
				testCase5(); // 用例5 配置格式正确，content 三层，解析正确
				break;
			case 6:
				testCase6(); // 用例6 配置格式正确，content 四层，解析正确
				break;
			case 7:
				testCase7(); // 用例7 配置格式正确，content 五层，解析正确
				break;
			case 8:
				testCase8(); // 用例8 配置格式错误，关键字错误，响应正确	
				break;
			case 9:
				testCase9(); // 用例9 格式错误，响应正确
				break;
			default:
				throw new IllegalArgumentException("Unexpected value: " + count);
		}
	}

	private static void testCase9() {
		System.out.println("----------- 用例9 格式错误，响应正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": \"id\": \"em_id\",\"__type__\": \"Object\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map);
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
	}

	private static void testCase8() {
		System.out.println("----------- 用例8 配置格式错误，关键字错误，响应正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern1\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"__type__\": \"Object\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map);
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}

	private static void testCase7() {
		System.out.println("----------- 用例7 配置格式正确，content五层，解析正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		// map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"five\":{\"name\": \"name\",\"__type__\": \"objEct\", \"employee\": {\"~~id\": \"em_id\",\"four\":{\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"__type__\": \"Object\",\"~~three\":{ \"name\": \"pre_comp_name\"}}}}}}}");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"five\":{\"name\": \"name\",\"employee\": {\"id\": \"em_id\",\"four\":{\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"three\":{ \"name\": \"pre_comp_name\"}}}}}}}");
		list.add(map);
		
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("id", "1");
		map2.put("name", "恒生电子");
		map2.put("em_id", "e_1");
		map2.put("em_name", "张三");
		map2.put("pre_comp_id", "1003");
		map2.put("pre_comp_name", "双汇发展");
		map2.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"five\":{\"name\": \"name\",\"employee\": {\"id\": \"em_id\",\"four\":{\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"three\":{ \"name\": \"pre_comp_name\"}}}}}}}");
		list.add(map2);
		
		Map<String, Object> map3 = new HashMap<String, Object>();
		map3.put("id", "1");
		map3.put("name", "恒生电子");
		map3.put("em_id", "e_1");
		map3.put("em_name", "赵四");
		map3.put("pre_comp_id", null);
		map3.put("pre_comp_name", "双汇发展");
		map3.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"five\":{\"name\": \"name\",\"employee\": {\"id\": \"em_id\",\"four\":{\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"three\":{ \"name\": \"pre_comp_name\"}}}}}}}");
		list.add(map3);
		
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}
	
	private static void testCase6() {
		System.out.println("----------- 用例6 配置格式正确，content四层，解析正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"four\":{\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"three\":{ \"name\": \"pre_comp_name\"}}}}}}");
		list.add(map);
		
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}

	private static void testCase5() {
		System.out.println("----------- 用例5 配置格式正确，content三层，解析正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"three\":{ \"name\": \"pre_comp_name\"}}}}}");
		list.add(map);
		
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}
	
	private static void testCase4() {
		System.out.println("----------- 用例4 配置格式正确，content二层，解析正确 -----------");
		// json格式转换
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"__type__\": \"Object\", \"employee\": {\"id\": \"em_id\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map);
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("id", "1");
		map2.put("name", "恒生电子");
		map2.put("em_id", "e_1");
		map2.put("em_name", "张三");
		map2.put("pre_comp_id", "1004");
		map2.put("pre_comp_name", "中国航发");
		map2.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map2);
		Map<String, Object> map3 = new HashMap<String, Object>();
		map3.put("id", "1");
		map3.put("name", "恒生电子");
		map3.put("em_id", "e_2");
		map3.put("em_name", "李四");
		map3.put("pre_comp_id", "8001");
		map3.put("pre_comp_name", "双汇发展");
		map3.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map3);
		Map<String, Object> map4 = new HashMap<String, Object>();
		map4.put("id", "2");
		map4.put("name", "阿里巴巴");
		map4.put("em_id", "s_1");
		map4.put("em_name", "赵刘");
		map4.put("pre_comp_id", "");
		map4.put("pre_comp_name", "");
		map4.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"employee\": {\"id\": \"em_id\",\"name\": \"em_name\",\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}}");
		list.add(map4);
		
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}
	
	private static void testCase3() {
		System.out.println("----------- 用例3 配置格式正确，content一层，解析正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{ \"~~emid\":\"em_id\", \"pre_comps\": {\"__type__\": \"Object\", \"id\": \"pre_comp_id\",\"~~name\": \"pre_comp_name\"}}}");
		list.add(map);
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("id", "1");
		map2.put("name", "恒生电子");
		map2.put("em_id", "e_1");
		map2.put("em_name", "张三");
		map2.put("pre_comp_id", "1004");
		map2.put("pre_comp_name", "中国航发");
		map2.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}");
		list.add(map2);
		Map<String, Object> map3 = new HashMap<String, Object>();
		map3.put("id", "1");
		map3.put("name", "恒生电子");
		map3.put("em_id", "e_2");
		map3.put("em_name", "李四");
		map3.put("pre_comp_id", "8001");
		map3.put("pre_comp_name", "双汇发展");
		map3.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}");
		list.add(map3);
		Map<String, Object> map4 = new HashMap<String, Object>();
		map4.put("id", "2");
		map4.put("name", "阿里巴巴");
		map4.put("em_id", "s_1");
		map4.put("em_name", "赵刘");
		map4.put("pre_comp_id", "");
		map4.put("pre_comp_name", "");
		map4.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"pre_comps\": {\"id\": \"pre_comp_id\",\"name\": \"pre_comp_name\"}}}");
		list.add(map4);
		
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}
	
	private static void testCase2() {
		System.out.println("----------- 用例2 配置格式正确，content无内容，响应正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		map.put("tech_ic_json_config", "{\"pattern\":\"default\",\"template\":\"default\",\"content\":{\"__type__\": \"Object\"}}");
		list.add(map);
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}

	private static void testCase1() {
		System.out.println("----------- 用例1 不加tech_ic_json_config字段，响应正确 -----------");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", "1");
		map.put("name", "恒生电子");
		map.put("em_id", "e_1");
		map.put("em_name", "张三");
		map.put("pre_comp_id", "1003");
		map.put("pre_comp_name", "中国航天");
		list.add(map);
		System.out.println(list);
		List<Map<String, Object>> processInternal = processInternal(list);
		System.out.println(processInternal);
		System.out.println();
	}

	public static List<Map<String, Object>> processInternal(List<Map<String, Object>> input) {
		// 组装规则
		Map<String, Object> map = assembleRule(input);
		if (map == null) {
			return input;
		}
		// 构造临时树
		@SuppressWarnings("unchecked")
		Map<String, Object> config = (Map<String, Object>) map.get("config");
		Map<String, Object> treeMap = constructTree(config, input);
		if (treeMap == null) {
			return input;
		}
		// 转换列表
		List<Map<String, Object>> changeList = changeTree(treeMap, config);
		@SuppressWarnings("unchecked")
		Map<String, String> type_map = (Map<String, String>) map.get("type_map");
		if (type_map.isEmpty()) {
			return changeList;
		}
		// 类型转换
		List<Map<String, Object>> resultList = changeTypeTree(changeList, type_map);
		return resultList;
	}

	/**
	 * 组装规则
	 * 
	 * @param input
	 * @return
	 */
	private static Map<String, Object> assembleRule(List<Map<String, Object>> input) {
		// 参数校验
		Map<String, Object> tempConfig = checkConfig(input);
		if (tempConfig == null) {
			return null;
		}
		// 组装配置
		List<String> cols = new ArrayList<String>();
		cols.add("tech_ic_json_config");
		Map<String, String> type_map = assembleList(cols, tempConfig, new HashMap<String, String>(), "content");
		for (Map.Entry<String, Object> entry : input.get(0).entrySet()) {
			if (!cols.contains(entry.getKey())) {
				tempConfig.put(entry.getKey(), entry.getKey());
			}
		}
		Map<String, Object> config = new HashMap<String, Object>();
		config.put("content", tempConfig);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type_map", type_map);
		map.put("config", config);
		return map;
	}

	private static Map<String, String> assembleList(List<String> cols, Map<String, Object> tempConfig, Map<String, String> map, String key) {
		for (Map.Entry<String, Object> entry : tempConfig.entrySet()) {
		    if (entry.getValue() instanceof Map) {
		    	@SuppressWarnings("unchecked")
				Map<String, Object> nextConfig = (Map<String, Object>) entry.getValue();
		    	assembleList(cols, nextConfig, map, entry.getKey());
	        } else {
	        	if (entry.getValue() != null) {
	        		if (OBJECT_TYPE.equals(entry.getKey())) {
		        		map.put(key, entry.getValue().toString());
		        	} else {
		        		cols.add(entry.getValue().toString());
		        	}
	        	}
	        }
		}
		tempConfig.remove(OBJECT_TYPE);
		return map;
	}

	/**
	 * 校验配置格式
	 * 
	 * @param map
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	private static Map<String, Object> checkConfig(List<Map<String, Object>> input) {
		if (input == null || input.isEmpty()) {
			System.out.println("未获取到参数！");
			return null;
		}
		Map<String, Object> map = input.get(0);
		if (map == null || map.isEmpty()) {
			System.out.println("未获取到参数！");
			return null;
		}
		if (!map.containsKey("tech_ic_json_config") || map.get("tech_ic_json_config") == null) {
			System.out.println("未获取到配置信息！");
			return null;
		}
		ObjectMapper mapper = new ObjectMapper();
		Map<String, Object> config = null;
		try {
			config = mapper.readValue(map.get("tech_ic_json_config").toString(), Map.class);
			if (!config.containsKey("pattern") || !"default".equals(config.get("pattern"))) {
				System.out.println("配置信息pattern错误！");
				return null;
			}
			if (!config.containsKey("template") || !"default".equals(config.get("template"))) {
				System.out.println("配置信息template错误！");
				return null;
			}
			if (!config.containsKey("content") || config.get("content") == null) {
				System.out.println("未获取到配置信息content！");
				return null;
			}
			if (!(config.get("content") instanceof Map)) {
				System.out.println("配置信息content格式错误！");
				return null;
			}
			config = (Map<String, Object>) config.get("content");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("配置信息格式转换错误！" + e.toString());
			return null;
		}
		return config;
	}

	/**
	 * 构建临时树
	 * 
	 * @param config
	 * @param input
	 */
	private static Map<String, Object> constructTree(Map<String, Object> config, List<Map<String, Object>> input) {
		Map<String, Object> map = null;
		@SuppressWarnings("unchecked")
		Map<String, Object> tempConfig = (Map<String, Object>) config.get("content");
		for (int i = 0; i < input.size(); i++) {
			map = constructValue(input.get(i), map, "content", tempConfig);
		}
		return map;
	}

	@SuppressWarnings("unchecked")
	private static Map<String, Object> constructValue(Map<String, Object> row, Map<String, Object> map,
			String prop, Map<String, Object> config) {
		if (map == null) {
			map = new LinkedHashMap<String, Object>();
		}
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
		if (map.containsKey(prop) && map.get(prop) != null) {
			resultMap = (LinkedHashMap<String, Object>) map.get(prop);
		}
		Map<String, Object> tempMap = new LinkedHashMap<String, Object>();
		if (config != null) {
			// 根据config中的属性及raw构造map的key，如1+恒生电子、2+阿里巴巴
			String key = null;
			for (Map.Entry<String, Object> entry : config.entrySet()) {
			    if(!(entry.getValue() instanceof Map)) {
			    	if (row.get(entry.getValue()) != null) {
			    		if (key != null) {
			        		key += "+" + (row.get(entry.getValue()) == null ? "" : row.get(entry.getValue()));
			        	} else {
			        		key = "" + (row.get(entry.getValue()) == null ? "" : row.get(entry.getValue()));
			        	}
			        	tempMap.put(entry.getKey(), row.get(entry.getValue()));
			    	}
		        }
			}
			if (key != null) {
				// 取map.propMap.key 为value如果没有,则构造value并放到map.propMap.key中
				for (Map.Entry<String, Object> entry : config.entrySet()) {
				    if (entry.getValue() instanceof Map) {
				    	Map<String, Object> resMap = new LinkedHashMap<String, Object>();
				    	Map<String, Object> newMap = new LinkedHashMap<String, Object>();
				    	if (key != null && resultMap.containsKey(key) && resultMap.get(key) != null) {
				    		newMap = (LinkedHashMap<String, Object>) resultMap.get(key);
						}
				    	Map<String, Object> newConfig = (Map<String, Object>) entry.getValue();
				    	resMap = constructValue(row, newMap, entry.getKey(), newConfig);
			            tempMap.put(entry.getKey(), resMap.get(entry.getKey()));
			        }
				}
				resultMap.put(key, tempMap);
			}
		}
		map.put(prop, resultMap);
		return map;
	}
	
	/**
	 * 转换列表
	 * 
	 * @param treeMap
	 * @param config 
	 * @return
	 */
	private static List<Map<String, Object>> changeTree(Map<String, Object> treeMap, Map<String, Object> config) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		@SuppressWarnings("unchecked")
		Map<String, Object> tempConfig = (Map<String, Object>) config.get("content");
		list = changeValue(list, treeMap, "content", tempConfig);
		return list;
	}

	@SuppressWarnings("unchecked")
	private static List<Map<String, Object>> changeValue(List<Map<String, Object>> list,
			Map<String, Object> treeMap, String prop, Map<String, Object> config) {
		if(treeMap.containsKey(prop) && treeMap.get(prop) != null) {
			Map<String, Object> propMap = (Map<String, Object>) treeMap.get(prop);
			for(Map.Entry<String, Object> entry : propMap.entrySet()){
				Map<String, Object> tempMap = new HashMap<String, Object>();
				Map<String, Object> tempValue = (Map<String, Object>) entry.getValue();
				for (Map.Entry<String, Object> entryConfig : config.entrySet()) {
					if (entryConfig.getKey().contains("~~")) {
						continue;
					}
					if(!(entryConfig.getValue() instanceof Map)) {
						tempMap.put(entryConfig.getKey(), tempValue.get(entryConfig.getKey()));
					} else {
						Map<String, Object> preMap = new HashMap<String, Object>();
						preMap.put(entryConfig.getKey(), tempValue.get(entryConfig.getKey()));
						Map<String, Object> tempConfig = (Map<String, Object>) entryConfig.getValue();
						List<Map<String, Object>> tempList = changeValue(new ArrayList<Map<String, Object>>(), preMap, entryConfig.getKey(), tempConfig);
						tempMap.put(entryConfig.getKey(), tempList);
					}
				}
				if (!tempMap.isEmpty()) {
					list.add(tempMap);
				}
			}
		}
		return list;
	}
	
	/**
	 * 列表对象类型转换
	 * 
	 * @param changeList
	 * @param type_map
	 * @return
	 */
	private static List<Map<String, Object>> changeTypeTree(List<Map<String, Object>> changeList,
			Map<String, String> type_map) {
		List<Map<String, Object>> list = changeType(changeList, type_map);
		return list;
	}

	private static List<Map<String, Object>> changeType(List<Map<String, Object>> changeList, Map<String, String> type_map) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (changeList != null && changeList.size() > 0) {
			for (int i = 0; i < changeList.size(); i++) {
				Map<String, Object> map = changeList.get(i);
				for(Map.Entry<String, Object> entry : map.entrySet()){
					if (entry.getValue() instanceof List) {
						@SuppressWarnings("unchecked")
						List<Map<String, Object>> propList = (List<Map<String, Object>>) entry.getValue();
						List<Map<String, Object>> changelist = changeType(propList ,type_map);
						if (type_map.containsKey(entry.getKey()) && "object".equalsIgnoreCase(type_map.get(entry.getKey()))) {
							if (!changelist.isEmpty()) {
								map.put(entry.getKey(), changelist.get(0));
							} else {
								map.put(entry.getKey(), new HashMap<>());
							}
						}
					}
				}
				list.add(map);
			}
		}
		return list;
	}
	
}
